import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Solution solution =new Solution();
        Scanner scanner=new Scanner(System.in);
        int[]array=new int[100];
        int n=scanner.nextInt();
        for (int i = 0; i < n; i++) {
            array[i]=scanner.nextInt();
        }
        System.out.println(solution.maxSales(array));
    }

    public static void main1(String[] args) {
        Solution1 solution =new Solution1();
        Scanner scanner=new Scanner(System.in);
        int[]array=new int[100];
        int n=scanner.nextInt();
        for (int i = 0; i < n; i++) {
            array[i]=scanner.nextInt();
        }
        int[] array1=solution.buildArray(array);
        for (int i = 0; i < n; i++) {
            System.out.println(array1[i]);
        }
    }
}

class Solution {
    public int maxSales(int[] sales) {
        int n=sales.length;
        int[] dp=new int[n];
        dp[0]=sales[0];
        for(int i=1;i<n;i++){
            dp[i]=Math.max(sales[i],sales[i]+dp[i-1]);
        }
        Arrays.sort(dp);
        return dp[n-1];
    }
}

class Solution1 {
    public int[] buildArray(int[] nums) {
        int n=nums.length;
        int[] res=new int[n];
        for (int i=0; i < n; i++){
            res[i]=nums[nums[i]];
        }
        return res;
    }
}